<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('质检上架单')" />
	<th:block th:include="include :: businessCSS" />
    <style>
        .layui-table-tool{display: none;}
    </style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="forminput"></div>
        <div style="text-align:center;background: #fff; padding: 15px;">
            <input type="button" style="width: 100px;background: rgb(0, 135, 250);padding: 7px;color: #fff;border: none;border-radius: 10px;cursor: pointe" lay-submit lay-filter="btn-add" id="btn-add" value="保存">
        </div>

        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<!-- <th:block th:include="include :: businessTableBtn" /> -->
<!-- <th:block th:include="include :: inlineJS" /> -->
<script th:inline="javascript">
	var fields = [[${fields}]];
    var fieldsList = [[${fieldsList}]];
	var fieldsHiddenList = [[${fieldsHiddenList}]];
	var moduleTable = [[${moduleTable}]];
	var enableEdit = [[${enableEdit}]];
	console.log(fieldsList,enableEdit,555777)
</script>
<script type="text/javascript">
	

var $,layer,form,table,laydate,element;//定义layui模块
// eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
	    headcom()
        nid=$('#nid').val()


		form.on('submit(btn-add)', function(data){
			var is_return = false//是否中断保存
            fieldsList.map((v,i)=>{
                if(v.fieldFrontRequired){
                    if(!$('#'+v.fields).val()){
                         layer.msg(v.fieldName+'不能为空')
                         is_return=true
                    }
                }
            })
            if(is_return) return;
            $.operate.post("/storage/stockcontrol/editpost",{'infoItems':JSON.stringify(data.field)},function(res){
                layer.msg(res.msg)
                if(res.code==0){
                    setTimeout(function(){
                        window.location.href = "/storage/stockcontrol/edit?guid="+res.data;
                    }, 1000);
                }
            	
            })

        })

		$('#allotPrice').blur(function(){
             var dbnum=$(this).val()
             var productNum=$('#productNum').val()
			 var sum=(+dbnum)*(+productNum)
			 $('#totalAllotPrice').val(sum)
			 
		})


		$(".fieldsimg").each(function(){
	    	var id=$(this).attr('name')
            upload.render({
                elem: '#'+id+'_upimg',
	            url: '/system/fileinfo/uploadmailimg',
	            accept: 'images',
	    		before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                      console.log(index, file, result)
                    });
                },
	            done: function (res) {
                    //如果上传失败
                    if (res.errno > 0) {
                        return layer.msg('上传失败');
                    }else{
	    				layer.msg('上传成功');
	    				$('#'+id).val(res.data[0])
	    				layui.$('#'+id+'_upimg').find('.upicon').addClass('layui-hide')
	    				layui.$('#'+id+'_upimg').find('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data[0]);
	    			}
                },error: function (err) {
                    //演示失败状态，并实现重传
	            	console.log(err)
                }
            });
        })


		$('.t_date').each(function(){
            var datetype=$(this).attr('datetype')
            laydate.render({
				elem:this
                ,type: datetype=='t_date'?'date':datetype=='t_datetime'?'datetime':datetype=='t_year'?'year':'month'
			})
		})
 	// beforeInit();//表单初始化之前的动作集合
 	// // layui.element.render();
 	// $.get("/storage/stockcontrol/listbynid?nid="+nid,function(data){
	// 	$.each(data.data,function(k,v){
	// 		dataStr.push(v);
	// 	});
	// 	// initTable();//初始化表格
	// });
	// toolbarEvent();//通用表格头部工具栏事件监听
	// toolEvent('ftable');//行event事件监听
	// monitorSort();//监听排序——重载赋值渲染
	// moneyCalculation();//表格编辑——资金计算
    // form.on('submit(btn-add)', function(data){
    //     $.operate.post("/storage/stockcontrol/editpost",{'infoMap':JSON.stringify(data.field)},function(res){
    //         layer.msg(res.msg)
    //         if(res.code==0){
    //             setTimeout(function(){
    //                 window.location.href = "/storage/stockcontrol/edit?nid="+res.data;
    //             }, 1000);
    //         }
        	
    //     })

    // })
})
</script>
</body>
</html>